
import Foundation
import UIKit

extension JX_TypeWrapper where T : UIView{

    var top : CGFloat {
        set{
            var newframe: CGRect = SELF.frame
            newframe.origin.y = newValue
            SELF.frame = newframe
        }
        get{
            return SELF.frame.origin.y
        }
    }
    
    var bottom : CGFloat {
        set{
            var newframe: CGRect = SELF.frame
            newframe.origin.y = newValue - SELF.frame.size.height
            SELF.frame = newframe
        }
        get{
            return SELF.frame.origin.y + SELF.frame.size.height
        }
    }
    
    var left : CGFloat{
        set{
             SELF.frame.origin.x = newValue
        }
        get{
            return SELF.frame.origin.x
        }
    }
    
    var right : CGFloat{
        set{
            SELF.frame.origin.x += newValue - (SELF.frame.origin.x + SELF.frame.size.width)
        }
        get{
            return SELF.frame.origin.x + SELF.frame.width
        }
    }
    

    var centerX : CGFloat {
        set{
            SELF.center.x = newValue
        }
        get {
            return SELF.center.x
        }
    }
    
    var centerY : CGFloat {
        set{
            SELF.center.y = newValue
        }
        get {
            return SELF.center.y
        }
    }


}

//MARK:FUNCTIONS
extension JX_TypeWrapper where T : UIView{
    
    func addShadow(x: CGFloat, y: CGFloat, opacity: CGFloat, blur: CGFloat, spread: CGFloat = 0, color: UIColor = UIColor.black) {
        SELF.layer.shadowPath = nil
        let radiusWidth: CGFloat = SELF.frame.width
        let radiusHeight: CGFloat = SELF.frame.height
        let shadowPath = UIBezierPath(rect: CGRect(x: x - spread, y: y - spread, width: radiusWidth + spread * 2, height: radiusHeight + spread * 2))
        SELF.layer.shadowColor = color.cgColor
        SELF.layer.shadowOffset = CGSize(width: x, height: y)
        SELF.layer.shadowOpacity = Float(opacity)
        SELF.layer.shadowRadius = blur //Here your control your blur
        SELF.layer.masksToBounds = false
        SELF.layer.shadowPath = shadowPath.cgPath //Here your control your spread
        SELF.layer.shouldRasterize = true
        SELF.layer.rasterizationScale = UIScreen.main.scale
    }
    
}
